import layout from "@/layouts/index.vue"
import { IBrowser, IHome } from "@icons/index"
import type { route } from "@type/route"

const pages = import.meta.glob("../pages/*.vue")

const menuRoutes: Array<route> = Object.entries(pages)
  .map(([filename, component]) => {
    const componentName = filename
      .split("/")
      .pop()
      ?.replace(/\.(vue|tsx|jsx)$/, "")

    return {
      path: `/${componentName}`,
      component: layout,
      icon: IBrowser,
      meta: {
        title: componentName,
        onlyOne: true,
      },
      children: [
        {
          path: "index",
          name: `${componentName}-index`,
          fullPath: `/${componentName}/index`,
          component,
          meta: {
            title: componentName,
          },
        },
      ],
    }
  })
  .filter(page => page.path != "/index")

export default [
  {
    path: "/",
    component: layout,
    icon: IHome,
    meta: {
      title: "主控台",
      onlyOne: true,
    },
    children: [
      {
        path: "dashboard",
        name: "dashboard",
        fullPath: "/dashboard",
        component: () => import("@pages/index.vue"),
        meta: {
          title: "主控台",
        },
      },
    ],
  },
  ...menuRoutes,
]
